//package org.example.config;
//
//import com.google.common.collect.Lists;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.ResponseEntity;
//import springfox.documentation.builders.ApiInfoBuilder;
//import springfox.documentation.builders.PathSelectors;
//import springfox.documentation.builders.RequestHandlerSelectors;
//import springfox.documentation.service.ApiInfo;
//import springfox.documentation.service.ApiKey;
//import springfox.documentation.service.AuthorizationScope;
//import springfox.documentation.service.SecurityReference;
//import springfox.documentation.spi.DocumentationType;
//import springfox.documentation.spi.service.contexts.SecurityContext;
//import springfox.documentation.spring.web.plugins.Docket;
//import springfox.documentation.swagger2.annotations.EnableSwagger2;
//
//import java.time.LocalDate;
//import java.util.List;
//
//@Configuration
//@EnableSwagger2
//public class SwaggerV2Config {
//
//    private static final String base_controller = "org.example.web.controller";
//
//    @Bean
//    public Docket createRestApi() {
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .enable(true)
//                .apiInfo(apiInfo())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage(base_controller))
//                .paths(PathSelectors.any())
//                .build()
//                .directModelSubstitute(LocalDate.class, String.class)
//                .genericModelSubstitutes(ResponseEntity.class)
//                .useDefaultResponseMessages(false)
//                .securityContexts(securityContexts())
//                .securitySchemes(securitySchemes());
//    }
//
//    private List<ApiKey> securitySchemes() {
//        return Lists.newArrayList(new ApiKey("Authorization", "Authorization", "header"));
//    }
//
//    private List<SecurityContext> securityContexts() {
//        SecurityContext context = SecurityContext.builder()
//                .securityReferences(defaultAuth())
//                //.forPaths(PathSelectors.regex("^(?!auth).*$"))
//                .build();
//
//        return Lists.newArrayList(context);
//
//    }
//
//    private List<SecurityReference> defaultAuth() {
//        AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
//        AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
//        authorizationScopes[0] = authorizationScope;
//
//        return Lists.newArrayList(new SecurityReference("Authorization", authorizationScopes));
//
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("RESTful API")
//                //版本号
//                .version("1.0")
//                //描述
//                .description("初始化api")
//                .build();
//    }
//
//
//}
